﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Is.Ex;
using Should.Fluent;

namespace Is.Test.Fluent
{
    [TestClass]
    public class ContainsDictionaryExtensionsExTest
    {
        [TestMethod]
        public void Test_ContainsKey()
        {
            IDictionary<int, string> sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Contains().Key(0).Should().Be.False();

            sampleDictionary.Add(0, "nulla");
            sampleDictionary.Contains().Key(0).Should().Be.True();

            sampleDictionary = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Key(0));

            IDictionary<string, int> sampleDictionary2 = new Dictionary<string, int>();
            sampleDictionary2.Contains().Key(string.Empty).Should().Be.False();
            sampleDictionary2.Contains().Key(null).Should().Be.False();
            sampleDictionary2.Contains().Key("alma").Should().Be.False();

            sampleDictionary2.Add("alma", 0);
            sampleDictionary2.Contains().Key(string.Empty).Should().Be.False();
            sampleDictionary2.Contains().Key(null).Should().Be.False();
            sampleDictionary2.Contains().Key("alma").Should().Be.True();

            sampleDictionary2.Add(string.Empty, 0);
            sampleDictionary2.Contains().Key(string.Empty).Should().Be.True();
            sampleDictionary2.Contains().Key(null).Should().Be.False();
            sampleDictionary2.Contains().Key("alma").Should().Be.True();

            
            sampleDictionary2 = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary2.Contains().Key(string.Empty));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary2.Contains().Key(null));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary2.Contains().Key("alma"));
        }

        [TestMethod]
        public void Test_Contains()
        {
            string nullstring = null;

            IDictionary<int, string> sampleDictionary = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Zero());
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().One());
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Exactly(0));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Exactly(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().AtLeast(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().AtLeast(0));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().AtLeast(2));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().NoMoreThan(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().NoMoreThan(2));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().NoMoreThan(0));


            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Contains().Zero().Should().Be.True();
            sampleDictionary.Contains().One().Should().Be.False();
            sampleDictionary.Contains().Exactly(0).Should().Be.True();
            sampleDictionary.Contains().Exactly(1).Should().Be.False();
            sampleDictionary.Contains().AtLeast(1).Should().Be.False();
            sampleDictionary.Contains().AtLeast(0).Should().Be.True();
            sampleDictionary.Contains().AtLeast(2).Should().Be.False();
            sampleDictionary.Contains().NoMoreThan(1).Should().Be.True();
            sampleDictionary.Contains().NoMoreThan(2).Should().Be.True();
            sampleDictionary.Contains().NoMoreThan(0).Should().Be.True();

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Contains().Zero().Should().Be.False();
            sampleDictionary.Contains().One().Should().Be.True();
            sampleDictionary.Contains().Exactly(1).Should().Be.True();
            sampleDictionary.Contains().Exactly(2).Should().Be.False();
            sampleDictionary.Contains().AtLeast(1).Should().Be.True();
            sampleDictionary.Contains().AtLeast(0).Should().Be.True();
            sampleDictionary.Contains().AtLeast(2).Should().Be.False();
            sampleDictionary.Contains().NoMoreThan(1).Should().Be.True();
            sampleDictionary.Contains().NoMoreThan(2).Should().Be.True();
            sampleDictionary.Contains().NoMoreThan(0).Should().Be.False();

            sampleDictionary = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Any(s => s.Value == "alma"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Item(new KeyValuePair<int, string>(0,"alma")));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().One(s => s.Value == "alma"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().One(new KeyValuePair<int, string>(0, "alma")));

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Contains().Any(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value == null).Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value == string.Empty).Should().Be.False();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Any(null));
            sampleDictionary.Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Contains().Item(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == null).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == string.Empty).Should().Be.False();
            sampleDictionary.Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();
            Func<string, bool> nullpredicate = null;
            

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Contains().Any(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Contains().Any(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value == null).Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value == string.Empty).Should().Be.False();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Any(null));
            sampleDictionary.Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Contains().Item(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Contains().One(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == null).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == string.Empty).Should().Be.False();
            sampleDictionary.Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();
            
            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Add(1, "alma");
            sampleDictionary.Add(2, "alom");
            sampleDictionary.Contains().Any(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Contains().Any(s => s.Value .Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Contains().Any(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value == null).Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value == string.Empty).Should().Be.False();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Any(null));
            sampleDictionary.Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Contains().Item(new KeyValuePair<int, string>(2, "alma")).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == "alom").Should().Be.True();
            sampleDictionary.Contains().One(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value.Is().StartsWith("alo")).Should().Be.True();
            sampleDictionary.Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == null).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == string.Empty).Should().Be.False();
            sampleDictionary.Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.True();
            sampleDictionary.Contains().One(new KeyValuePair<int, string>(2, "alma")).Should().Be.False();
            
            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Add(1, "alma");
            sampleDictionary.Add(2, "alom");
            sampleDictionary.Add(3, null);
            sampleDictionary.Contains().Any(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Contains().Any(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Contains().Any(s => s.Value == null).Should().Be.True();
            sampleDictionary.Contains().Any(s => s.Value == string.Empty).Should().Be.False();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Contains().Any(null));
            sampleDictionary.Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Contains().Item(new KeyValuePair<int, string>(2, "alma")).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == "alom").Should().Be.True();
            sampleDictionary.Contains().One(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value.Is().Not.Null() && s.Value.Is().StartsWith("alo")).Should().Be.True();
            sampleDictionary.Contains().One(s => s.Value.Is().Not.Null() && s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Contains().One(s => s.Value == null).Should().Be.True();
            sampleDictionary.Contains().One(s => s.Value == string.Empty).Should().Be.False();
            sampleDictionary.Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Contains().One(new KeyValuePair<int, string>(2, "alma")).Should().Be.False();
            
        }

    }
}
